﻿using System.Diagnostics;
using System.Threading.Tasks;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.Tests.Helpers;
using Xunit;
using Xunit.Abstractions;
using Sustainalytics.Synchronization.Interface;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.Tests
{
    public class ComprehensiveEsgSyncTests
    {
        private readonly ITestOutputHelper output;

        public ComprehensiveEsgSyncTests(ITestOutputHelper output)
        {
            Debug.Listeners.Add(new DefaultTraceListener());
            this.output = output;
        }

        [Fact]
        public async Task StartAsync()
        {
            var stopWatch = Stopwatch.StartNew();
            output.WriteLine("Test started");

            ILogger logger = new TestLogger();
            var container = SimpleInjectorConfig.Register(logger, TestConnectionStrings.GAConnectionStrings);
            var comprehensivceEsgSync = container.GetInstance<ComprehensiveEsgSync>();
            var resolvedComprehensiveEsgCompanies = await comprehensivceEsgSync.StartAsync().ConfigureAwait(false);
            if (resolvedComprehensiveEsgCompanies == 0)
                logger.Log("There are no core ESG companies to get from the back-office system");
            stopWatch.Stop();
            var elapsed = stopWatch.Elapsed.Seconds;
            output.WriteLine(elapsed.ToString());
        }
    }
}
